//
//  MFAPMCrashMonitorModel.m
//  MFAPMManager
//
//  Created by zhang liyu on 2019/5/26.
//

#import "MFAPMCrashMonitorModel.h"

#import "MFAPMUtility.h"

@implementation MFAPMCrashMonitorModel

#pragma mark - Life Circle

- (instancetype)init{
    self = [super init];
    if(self){
        [self configPropertyActions];
    }
    return self;
}

- (void)configPropertyActions{
    
    //初始化Model的公共属性
    
    self.eventType = 2;
    
    _cpuRate = [[NSString stringWithFormat:@"%.2f%%", [MFAPMUtility cpuUsage]] copy];
    
    _memoryRate = [[NSString stringWithFormat:@"%.2f%%", [MFAPMUtility memoryUsedPercent]] copy];
    
    _threadName = [NSThread currentThread].name.length > 0 ? [NSThread currentThread].name : ([NSThread currentThread].description ? : @"");
    
    _processName = ([[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey]) ? : @"";
    
    _systemStack = [[MFAPMUtility currentViewControllerPath] componentsJoinedByString:@"->"];
}

#pragma mark - Data Config Actions

- (void)configExtend{
    
    NSMutableDictionary *customInfoDict = [NSMutableDictionary dictionary];
    
    [customInfoDict setObject:@(_isSignal) forKey:@"isSignal"];
    [customInfoDict setObject:@(_signal) forKey:@"signal"];
    
    [customInfoDict setObject:(_leakVCName ? : @"") forKey:@"leakVCName"];
    [customInfoDict setObject:(_leakFuncName ? : @"") forKey:@"leakFuncName"];
    
    [customInfoDict setObject:(_zombineClassName ? : @"") forKey:@"zombineClassName"];
    [customInfoDict setObject:(_zombineFuncName ? : @"") forKey:@"zombineFuncName"];
    [customInfoDict setObject:(_zombineCallerAddress ? : @"") forKey:@"zombineCallerAddress"];
    
    _extend = [MFAPMUtility convertJSONStringFromObject:customInfoDict] ? : @"";
    
    //当没有调用栈时，直接保存当前的扩展信息
    if(_stack.length == 0){
        _stack = _extend;
    }
}

@end
